<?php

namespace App\Model\Admin;

use Illuminate\Database\Eloquent\Model;
use DB;
class Cat extends Model
{
    protected $table = "cat";
    protected $fillable = ['cat_name','pid'];
    public $timestamps = false;
       /**
     * 递归显示版块
     *
     * @param  array  $arr
     * @return  array
     */
    public static function tree($arr,$id=0,$lev=0){
        static $catinfo = [];
        foreach($arr as  $v){
           if($v->pid == $id){
            $v->lev = $lev;
            $catinfo[] = $v;
            self::tree($arr,$v->id,$lev+1);
           }
        }
        return $catinfo;
    }



    
    public static function dele($id){
        $count = DB::table('cat')->where('pid',$id)->count();
        if($count>0){
            $arr = DB::table('cat')->where('pid',$id)->get();
                foreach($arr as $val){
                     self::dele($val->id);
                  
                }

        }
        DB::table('cat')->where('id',$id)->delete();
    }

}
